<template>
  <div class="app">
    <van-nav-bar title="设置" left-text="" left-arrow @click="backlink()" />
    <div class="recommend-teacher-box">
      <div class="setting-content">
        <van-cell-group inset>
          <van-cell title="账号设置" is-link />
          <van-cell title="更改密码" is-link to="/editpassword" />
        </van-cell-group>
      </div>
      <div class="setting-content">
        <van-cell-group inset>
          <van-cell title="清理本地缓存" is-link />
          <van-cell title="消息通知" is-link />
          <van-cell title="意见反馈" is-link />
          <van-cell title="联系客服" is-link />
          <van-cell title="鼓励一下" is-link />
        </van-cell-group>
      </div>

      <div class="setting-content">
        <van-cell-group inset>
          <van-cell title="升级版本" is-link />
          <van-cell title="关于我们" is-link />
        </van-cell-group>
      </div>

      <van-button
        round
        block
        type="primary"
        style="width: 80%; margin-top: 20px"
        @click="logout"
        >退出登录</van-button
      >
    </div>
  </div>
</template>

<script>
import { userlogout } from "@/http/request.js";
import { showToast, showConfirmDialog } from "vant";
import { useStore } from "@/store/index.js";
export default {
  data() {
    return {
      uid: "",
    };
  },
  methods: {
    inituserinfo() {
      const store = useStore();
      const userinfo = store.getUserStoreinfo;
      this.uid = userinfo.uid;
    },
    logout() {
      showConfirmDialog({
        title: "退出登录",
        message: "你确定退出登录吗？",
      })
        .then(() => {
          userlogout({ uid: this.uid }).then((res) => {
            if (res.code == 0) {
              localStorage.clear();
              const store = useStore();
              store.setUserinfo();
              store.setStoreinfo();
              store.setStoreTimestamp();
              store.setStoreCityName();
              store.setActivemenu('homepage');
              this.$router.push("./");
              showToast(res.msg);
            } else {
              showToast(res.msg);
            }
          });
        })
        .catch(() => {
          // on cancel
        });
    },
    backlink() {
      this.$router.back();
    },
  },
  mounted() {
    this.inituserinfo();
  },
};
</script>

<style scoped>
.app {
  height: 100vh;
  background-color: #f5f3f3;
}

.recommend-teacher-box {
  width: 100%;
  padding-top: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}

.setting-content {
  width: 100%;
  padding-bottom: 15px;
}
</style>